package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.ApnOperTypeAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;

import org.springframework.stereotype.Service;

/**
 *
 */
@Service
@AttrHandler(ApnOperTypeAttrHandler.class)
public class ApnOperTypeAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 如果操作类型不是 变更地址池 则隐藏 终端地址池(主) 和 终端地址池(备)。
        if (!KiteStringUtils.isEqual(attr.getValue(), "100007392")) {
            LocalAttrHelper.hideAndNullable(inst, "200004011", "200004012");
        }
        // 如果操作类型是 变更地址池 ，终端地址池(主) 和 终端地址池(备)已经展示了，这里暂不处理
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {
        // 如果操作类型选择新装
        if (KiteStringUtils.isEqual(attr.getValue(), "100004575")) {
            KiteAttr speedAttr = inst.getAttr("200004001"); //细分业务类型
            if (!KiteObjectUtils.isEmpty(speedAttr) && KiteStringUtils.isNotEmpty(speedAttr.getValue()) && "100006960".equals(speedAttr
                .getValue())) { // 互联网GRE
                LocalAttrHelper
                    .showAndNonnull(inst, "200004135", "200002833", "200004004", "200004006", "200004007", "200004009",
                        "200004010", "200004013", "200004084");
                LocalAttrHelper.showAndNull(inst, "200004003");
                LocalAttrHelper.hideAndNullable(inst, "200004005");
            }
            if (!KiteObjectUtils.isEmpty(speedAttr) && KiteStringUtils.isNotEmpty(speedAttr.getValue()) && "100006961".equals(speedAttr
                .getValue())) { // 互联网L2TP
                LocalAttrHelper
                    .showAndNonnull(inst, "200004135", "200002833", "200004004", "200004007", "200004013", "200004017", "200004084");
                LocalAttrHelper.showAndNull(inst, "200004003");
                LocalAttrHelper.hideAndNullable(inst, "200004008", "200004005");
            }
            if (!KiteObjectUtils.isEmpty(speedAttr) && KiteStringUtils.isNotEmpty(speedAttr.getValue()) && "100006962".equals(speedAttr
                .getValue())) { // 专线GRE
                LocalAttrHelper
                    .showAndNonnull(inst, "200004135", "200002833", "200004004", "200004009", "200004010", "200004013",
                        "200004084", "200001808");
                LocalAttrHelper.showAndNull(inst, "200004242", "200004003");
                LocalAttrHelper.hideAndNullable(inst, "200004005");
            }
            if (!KiteObjectUtils.isEmpty(speedAttr) && KiteStringUtils.isNotEmpty(speedAttr.getValue()) && "100006963".equals(speedAttr
                .getValue())) { // 专线L2TP
                LocalAttrHelper.showAndNonnull(inst, "200004135", "200002833", "200004004", "200001808", "200004017", "200004084");
                LocalAttrHelper.showAndNull(inst, "200004242", "200004003");
                LocalAttrHelper.hideAndNullable(inst, "200004005");
            }
        }
        // 变更名单
        if (KiteStringUtils.isNotEmpty(attr.getValue()) && KiteStringUtils.isEqual(attr.getValue(), "100007391")) {
            LocalAttrHelper.showAndNonnull(inst, "200004004");
        }
    }
}
